import { defineStore } from "pinia";
import { ref } from "vue";
import type { Account, Auth, LoginLog } from "../model/loginModel";
import { login } from "@/apis/login";


export const useAuthSotre= defineStore("user",()=>{

    const token=ref("");
    const account=ref<Account>({});
    const loginLog=ref<LoginLog>({});

    const loginApi=async (data:Auth)=>{

      const res=await login(data).catch(()=>undefined);
      if(res){

        token.value=res.token;
        account.value=res.model;
        loginLog.value=res.loginLog;

      }

      return res; 
    }

    return{
        token,account,loginLog,loginApi
    }


},{
    persist:true
}


)